package com.jyh.homework.homework5;

/**
 * @Author JYH
 * @Date 2024/8/7 17:12
 * @Description 设计一个多线程的程序如下：设计一个火车售票模拟程序。
                假如火车站要有100张火车票要卖出，现在有5个售票点同时售票，用5个线程模拟这5个售票点的售票情况。
 */
public class HW1 {
    public static void main(String[] args) {
        sale sale = new sale();
        Thread t1 = new Thread(sale, "售票口1");
        //Thread t2 = new Thread(sale, "售票口2");
        //Thread t3 = new Thread(sale, "售票口3");
        //Thread t4 = new Thread(sale, "售票口4");
        //Thread t5 = new Thread(sale, "售票口5");
        t1.setDaemon(true);
        //t2.setDaemon(true);
        //t3.setDaemon(true);
        //t4.setDaemon(true);
        //t5.setDaemon(true);
        t1.start();
        //t2.start();
        //t3.start();
        //t4.start();
        //t5.start();

        for (int i = 1; i <= 100; i++) {
            System.out.println(Thread.currentThread().getName()+"已经卖出第"+i+"张火车票");
            if (i==100){
                try {

                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}
class sale implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"已经卖出第"+i+"张火车票");
        }
    }
}